<template>
	<div id="mailList">
		<div class="i_maxW">
			<div class="u_crumbs">
				<router-link to="/personal/index">个人中心</router-link>
				<strong>
					<router-link to="/personal/journal/index"><i>></i>我的日记</router-link>
				</strong>
				<strong><i>></i>写日记</strong>
			</div>
			<!--  -->
			<div class="u_resource">
				<div class="edito">
					<div class="editoH">
						<el-input v-model.trim="nameInput" min="3" max="20"  placeholder="请输入标题, 20个字符内" maxlength="20"></el-input>
					</div>
					<template>
						<div id="edito">
							<Ueditor  v-model="profile" :writeMsg="profile" id="profile" :config="config1"  ref="option"></Ueditor> 
					</div>
				</template>
				<div class="editoB clear">
					<div class="editoB_l fl">
						<span>权限</span>
						<template>
							<el-radio v-model="authority" label="1">公开</el-radio>
							<el-radio v-model="authority" label="0">私密</el-radio>
						</template>
					</div>
					<div class="editoB_r buttonCSS fr">
						<el-button type="primary" plain @click="cancelJournal()">取消</el-button>
						<el-button id="add" type="primary" @click="submitJournal()" v-preventReClick>发表</el-button>
					</div>
				</div>
			</div>
		</div>

	</div>
</div>
</template>

<script>

	// import Ueditor from '../base/Ueditor.vue';
	import emotions from '../../../public/emotions.json';
	import Ueditor from '../base/Ueditor.vue';
	   export default {
	   	components: {Ueditor},
	   	data(){
	   		return {
	   			profile: '',
	   			authority: '1',
	   			nameInput: '',
	   	
	   			isDisable: false,
	   			textLength: 0,
	   			textBol: false,

	   			config1: {
	   			 	zIndex: 3,
	   			 	wordCount:true,
		        	textIndent: 0,
		        	maximumWords: 1000,
		        	elementPathEnabled: false,/*元素路径*/
		        	enableAutoSave: false,
					autoHeightEnabled: false,
					autoFloatEnabled: false,//不允许滚动时固定在顶部
					initialContent:'请输入内容...',   //初始化编辑器的内容,也可以通过textarea/script给值，看官网例子
					autoClearinitialContent:true, //是否自动清除编辑器初始内容，注意：如果focus属性设置为true,这个也为真，那么编辑器一上来就会触发导致初始化的内容看不到了
					initialFrameWidth: '100%',
					initialFrameHeight: 420,
					// serverUrl: this.BASE_URL+"/public/_/UEditor/1.4.3//php/controller.php?action=uploadimage",
					BaseUrl: this.BASE_URL,
					serverUrl: this.BASE_URL+"/static/_/UEditor/1.4.3/php/controller.php?action=uploadimage",
					UEDITOR_HOME_URL: process.env.BASE_URL ? process.env.BASE_URL + 'ueditor/' : '/public/ueditor/',
					toolbars: [
						['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'pasteplain',  'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc','fullscreen',  'simpleupload','link', 'justifyleft', 'justifyright', 'justifycenter', 'lineheight', 'fontfamily', 'fontsize', 'undo', 'redo']
					]
		        },
	   		};
	   	},

	   	mounted(){


		},
		methods: {
			/**
			 * 提交数据
			 * @DateTime 2020-03-05T11:20:40+0800
			 */
			submitJournal() {

				let data = {
					create_id : this.$g.user_id,
					name : this.nameInput,
					profile : this.profile,
					authority : this.authority 
				};
				// 验证数据
				if (this.nameInput === '' || this.profile === '') {
					this.$message.error('请输入内容');
					return
				}

				if (this.$refs.option.getContentTxt().length > this.config1.maximumWords) {
					return this.$message.error('字数超出最大允许值，服务器可能拒绝保存！')
				}
		
				let success = (res => {		
					this.$message.success(res.msg)
					setTimeout(() => {
						this.$router.push({path: '/personal/journal/index'})  
					}, 800)
				})
				this.$ajax.post('/api/resource/journal',data,{func:{success:success}})	
			},
			cancelJournal() {
				this.$router.back(-1)
			}
		}
	}
</script>